<template>
	<view class="app-container">
		<view class="header">
			<view class="header-left">
				{{type==6?'文打卡':'武打卡'}}
			</view>
			<view class="header-right">
				<view class="header-right-row">
					累计打卡
					<text>{{info.count}}</text>
					次
				</view>
				<view class="header-right-row">
					累计打卡
					<text>{{info.score}}</text>
					分
				</view>
			</view>
		</view>
		<view class="btns" v-if="type != 6">
			<button type="default" class="button" @click="changeType(0)" :class="type==0?'button-select':''">超慢跑</button>
			<button type="default" class="button" @click="changeType(4)" :class="type==4?'button-select':''">自我训练</button>
		</view>
		<view class="record-list">
			<view style="display: flex;justify-content: center;align-items: center; height: 300px;width: 100%;color:#999999" v-if="!info.list.length">
				暂无打卡记录
			</view>
			<view class="record-item" v-for="(item,index) in info.list" v-else>
				<view class="item-left">
					<image :src="item.pic" mode="widthFix" @click="open(item.pic)"></image>
					<text class="time">{{item.createtime}}</text>
				</view>
				<view class="item-right">{{item.content}}</view>
			</view>
			
		</view>
	</view>
	<uni-popup ref="popup" type="center" :animation="false">
		<div style="position: fixed;width: 100vw;height: 100vh;display: flex;justify-content: center;align-items: center;" @click="close">
			<image :src="popImgUrl" mode="widthFix" style="max-width: 80%;"></image>
		</div>
	</uni-popup>
</template>

<script>
import { checkInList, personMessageList } from '../../api';
import { config } from '../../utils/utils';
	export default {
		data() {
			return {
				popImgUrl: '',
				type: 0,
				page: 1,
				info: {
					count: 0,
					score: 0,
					list: []
				}
			}
		},
	 // onPullDownRefresh() {
		// 	// 实现下拉刷新的数据更新逻辑
		// 	console.log('下拉刷新事件被触发');
	 
		// 	// 假设这里是异步获取数据的操作
		// 	setTimeout(() => {
		// 		// 数据更新完毕后，停止下拉刷新动画
		// 		uni.stopPullDownRefresh();
		// 	}, 2000);
		// },
		
		  onPullDownRefresh() {
		    this.page = 1;
		    this.getListInfo();
		  },
		  onReachBottom() {
				 this.page += 1;
				 this.getListInfo();
		  },
		// https://trip.chinahood.net/api/checkin/checkinList? openId=ohiEf7fXD2LLbjhJFo0cUGsLOXA0&catid=4&page=1
		onLoad(options) {
			this.type = options.type;
		// 在页面的 JavaScript 部分
			this.getListInfo();
		},
		methods: {
			changeType(type) {
				this.type = type;
				this.page = 1;
				this.getListInfo();
			},
			open(pic) {
				this.popImgUrl = pic
				this.$refs.popup.open('top')
				// uni.hideNavigationBar();
				// uni.hideNavigationBarLoading();
				// 隐藏导航栏
			},
			close() {
				this.$refs.popup.close()
				// uni.showNavigationBar();
			},
			getListInfo() {
				let userInfo = uni.getStorageSync(config.userInfo);
				let openId = userInfo.openid;
				// this.info.score = userInfo.score;
				// catid: 4,
				let param = {
					openId: openId,
					type: this.type,
					page: this.page
				}
				checkInList(param).then(res=>{
					if(this.page > 1) {
						if(res.info) this.info.list = this.info.list.concat(res.info);
						if(res.score) this.info.score = res.score;
						if(res.count) this.info.count = res.count;
					}else {
						if(res.info) {
							this.info.list = res.info;
							this.info.score = res.score;
							this.info.count = res.count;
						}else {
							this.info =  {
								count: 0,
								score: 0,
								list: []
							};
						}
					}
					uni.stopPullDownRefresh(); // 停止下拉刷新

				})
				return;
				
				// "createtime": "2024-06-26",
				// "content": "打卡测试",
				// "title": "Ash-自我打卡记录-2024-06-26", "pic": "https://img0.baidu.com/it/"
				//模拟数据
				for (var i = 0; i < 10; i++) {
					let param = {
						id: '1',//新闻页id
						src: '',//新闻默认图
						time: '2024-06-03',//打卡时间
						content: "汇丰发布为第六届中国企业看中国2023》调查报告。报告显示，受中国疫后经济复苏的鼓舞，超过八成（87%）受访海外企业表示将拓展中国业务布局。",//正文描述
					};
					this.info.list.push(param);
				}
			}
			
		},
	}
</script>

<style lang="scss" scoped>
	.app-container {
		// width: 100%;
		display: flex;
		width: calc(100% - 60rpx);
		margin-left: 30rpx;
		.header {
			width: 100%;
			// height: 92rpx;
			display: flex;
			justify-content: space-between;
			.header-left {
				font-size: 36rpx;
				color: #333333;
			}
			.header-right {
				color: #333333;
				display: flex;
				flex-direction: row;
				vertical-align: bottom;
				.header-right-row {
					font-size: 24rpx;
					letter-spacing: -1px;
					text {
						font-size: 36rpx;
					}
					&:last-child {
						margin-left: 30rpx;
					}
				}
			}
		}
		.btns {
			margin-top: 20rpx;
			height: 80rpx;
			width: 100%;
			display: flex;
			justify-content: space-between;
			align-items: center;
			.button {
				// width: 50%;
				// height: 60rpx;
				// line-height: 60rpx;
				// text-align: center;
				display: flex;
				justify-content: center;
				align-items: center;
				background: #999999;
				color: #ffffff;
				border-radius: 10rpx;
				width: 340rpx;
				height: 80rpx;
				font-size: 30rpx;
				margin: 0;
				padding: 0;
			}
			.button-select {
				background: #fbb03b;
			}
		}
		.record-list {
			width: 100%;
			display: flex;
			flex-direction: column;
			.record-item {
				overflow: hidden;
				
				padding: 30rpx 0;
				display: flex;
				flex-direction: row;
				// justify-content: space-between;
				// height: 250rpx;
				border-top: 1px solid #F8F8F8;
				.item-left {
					display: flex;
					flex-direction: column;	
					width: 160rpx;
					image {
						width: 160rpx;
						// height: 160rpx;
						// border: 1px solid #808080;
						// border-radius: 5px;
						// background: #808080;
					}
					.time {
						margin-top: 10rpx;
						font-size: 24rpx;
						color: #808080;
					}
				}
				.item-right {
					display: inline-block;
					height: 192rpx;
					margin-top: -10rpx;
					margin-left: 40rpx;
					font-size: 24rpx;
					line-height: 48rpx;
					word-wrap: wrap;
					color: #4D4D4D;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 4; /* 定义文本的行数 */
					overflow: hidden;
					text-overflow: ellipsis;
				}
			}
		}
	}

</style>
